<template>
  <div class="permission-container">
    <!-- 标签页切换不同管理功能 -->
    <el-tabs v-model="activeTab" type="card">
      <el-tab-pane label="资源管理" name="resource">
        <div class="section-container">
          <div class="header-actions">
            <el-button type="primary" @click="handleAddResource">添加资源</el-button>
          </div>

          <!-- 资源列表 -->
          <h3>所有资源列表</h3>
          <el-table :data="paginatedResourceList" border stripe v-loading="resourceLoading" class="table-adaptive">
            <el-table-column prop="name" label="资源名称" width="400"></el-table-column>
            <el-table-column prop="resourceDesc" label="资源描述" min-width="350"></el-table-column>
            <el-table-column label="操作" width="200" fixed="right">
              <template #default="scope">
                <el-button type="primary" size="small" @click="handleEditResource(scope.row)">编辑</el-button>
                <el-button type="danger" size="small" @click="handleDeleteResource(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>

          <!-- 资源分页 -->
          <div class="pagination-container">
            <el-pagination
              @size-change="handleResourceSizeChange"
              @current-change="handleResourceCurrentChange"
              :current-page="resourceCurrentPage"
              :page-sizes="[5, 10, 20, 50]"
              :page-size="resourcePageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="resourceList.length">
            </el-pagination>
          </div>
        </div>

        <!-- 资源编辑对话框 -->
        <el-dialog
          :title="resourceForm.resourceId ? '编辑资源' : '新增资源'"
          :visible.sync="resourceDialogVisible"
          width="500px"
          @close="resetResourceForm"
        >
          <el-form :model="resourceForm" ref="resourceFormRef" :rules="resourceRules" label-width="100px">
            <el-form-item label="资源名称" prop="name">
              <el-input v-model="resourceForm.name" placeholder="请输入资源名称"></el-input>
            </el-form-item>
            <el-form-item label="资源描述" prop="resourceDesc">
              <el-input type="textarea" v-model="resourceForm.resourceDesc" placeholder="请输入资源描述"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="resourceDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="submitResourceForm">确 定</el-button>
          </div>
        </el-dialog>
      </el-tab-pane>

      <el-tab-pane label="角色资源管理" name="roleResource">
        <div class="section-container">
          <div class="query-form">
            <el-form :inline="true" :model="roleResourceQuery">
              <el-form-item label="角色">
                <el-select v-model="roleResourceQuery.rolesId" placeholder="请选择角色" style="width:200px">
                  <el-option :key="0" label="超级管理员" :value="0"></el-option>
                  <el-option :key="1" label="管理员" :value="1"></el-option>
                  <el-option :key="2" label="负责人" :value="2"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="fetchRoleResourceList">查询</el-button>
                <el-button type="info" @click="resetRoleResourceQueryForm">清空</el-button>
                <el-button type="success" @click="handleAddRoleResource">新增角色资源</el-button>
              </el-form-item>
            </el-form>
          </div>

          <!-- 所有角色资源关联列表 -->
          <h3>角色资源列表</h3>
          <el-table
            :data="roleResourceList.length > 0 ? roleResourceList : paginatedRolesResources"
            border
            stripe
            v-loading="allRolesResourcesLoading || roleResourceLoading"
            class="table-adaptive"
          >
            <el-table-column label="角色名称" width="350">
              <template #default="scope">
                <span>{{ getRoleNameById(scope.row.rolesId) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="资源名称" width="380">
              <template #default="scope">
                <span>{{ getResourceNameById(scope.row.resourceId) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="资源描述" min-width="250">
              <template #default="scope">
                <span>{{ getResourceDescById(scope.row.resourceId) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="180" fixed="right">
              <template #default="scope">
                <el-button type="primary" size="small" @click="handleEditRoleResource(scope.row)">编辑</el-button>
                <el-button type="danger" size="small" @click="handleDeleteRoleResource(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>

          <!-- 角色资源分页 -->
          <div class="pagination-container">
            <el-pagination
              @size-change="handleRoleResourceSizeChange"
              @current-change="handleRoleResourceCurrentChange"
              :current-page="roleResourceCurrentPage"
              :page-sizes="[5, 10, 20, 50]"
              :page-size="roleResourcePageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="roleResourceQuery.rolesId ? roleResourceList.length : allRolesResources.length">
            </el-pagination>
          </div>
        </div>

        <!-- 角色资源编辑对话框 -->
        <el-dialog
          :title="roleResourceForm.id ? '编辑角色资源' : '新增角色资源'"
          :visible.sync="roleResourceDialogVisible"
          width="500px"
          @close="resetRoleResourceForm"
        >
          <el-form :model="roleResourceForm" ref="roleResourceFormRef" :rules="roleResourceRules" label-width="100px">
            <el-form-item label="角色名称" prop="rolesId">
              <el-select v-model="roleResourceForm.rolesId" placeholder="请选择角色" style="width:100%">
                <el-option :key="0" label="超级管理员" :value="0"></el-option>
                <el-option :key="1" label="管理员" :value="1"></el-option>
                <el-option :key="2" label="负责人" :value="2"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="资源描述" prop="resourceId">
              <el-select v-model="roleResourceForm.resourceId" placeholder="请选择资源" style="width:100%">
                <el-option
                  v-for="resource in resourceList"
                  :key="resource.resourceId"
                  :label="resource.resourceDesc"
                  :value="resource.resourceId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="roleResourceDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="submitRoleResourceForm">确 定</el-button>
          </div>
        </el-dialog>
      </el-tab-pane>

      <el-tab-pane label="用户角色管理" name="userRole">
        <div class="section-container">
          <div class="header-actions">
            <el-button type="primary" @click="fetchAllAdmins">刷新管理员列表</el-button>
          </div>

          <!-- 所有管理员角色列表 -->
          <h3>管理员角色列表</h3>
          <el-table :data="adminList" border stripe v-loading="adminLoading">
            <el-table-column prop="name" label="管理员名称" width="450"></el-table-column>
            <el-table-column label="角色" width="450">
              <template #default="scope">
                <span>{{ getRoleNameById(scope.row.role) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="280">
              <template #default="scope">
                <el-button type="primary" size="small" @click="handleAssignRole(scope.row)">分配角色</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <!-- 角色分配对话框 -->
        <el-dialog
          title="分配角色"
          :visible.sync="roleAssignDialogVisible"
          width="500px"
        >
          <el-form :model="roleAssignForm" ref="roleAssignFormRef" :rules="roleAssignRules" label-width="100px">
            <el-form-item label="管理员ID" prop="adminId">
              <el-input v-model="roleAssignForm.adminId" disabled></el-input>
            </el-form-item>
            <el-form-item label="管理员名称" prop="adminName">
              <el-input v-model="roleAssignForm.adminName" disabled></el-input>
            </el-form-item>
            <el-form-item label="当前角色">
              <el-input v-model="roleAssignForm.currentRoleName" disabled></el-input>
            </el-form-item>
            <el-form-item label="分配角色" prop="role">
              <el-select v-model="roleAssignForm.role" placeholder="请选择角色" style="width:100%">
                <el-option :key="0" label="超级管理员" :value="0"></el-option>
                <el-option :key="1" label="管理员" :value="1"></el-option>
                <el-option :key="2" label="负责人" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="roleAssignDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="submitRoleAssign">确 定</el-button>
          </div>
        </el-dialog>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      activeTab: 'resource',

      // 资源管理
      resourceList: [],
      resourceLoading: false,
      resourceDialogVisible: false,
      resourceForm: {
        resourceId: null,
        name: '',
        resourceDesc: ''
      },
      resourceRules: {
        name: [
          { required: true, message: '请输入资源名称', trigger: 'blur' }
        ]
      },
      resourceCurrentPage: 1,
      resourcePageSize: 10,

      // 角色资源管理
      roleResourceList: [],
      roleResourceLoading: false,
      roleResourceDialogVisible: false,
      roleResourceQuery: {
        rolesId: ''
      },
      roleResourceForm: {
        id: null,
        rolesId: '',
        resourceId: ''
      },
      roleResourceRules: {
        rolesId: [
          { required: true, message: '请输入角色ID', trigger: 'blur' }
        ],
        resourceId: [
          { required: true, message: '请输入资源ID', trigger: 'blur' }
        ]
      },
      roleResourceCurrentPage: 1,
      roleResourcePageSize: 10,

      // 用户角色管理
      userRoleList: [],
      userRoleLoading: false,
      userRoleDialogVisible: false,
      userRoleQuery: {
        adminId: ''
      },
      userRoleForm: {
        adminId: '',
        role: ''
      },
      userRoleRules: {
        role: [
          { required: true, message: '请输入角色ID', trigger: 'blur' }
        ]
      },

      // 所有管理员
      adminList: [],
      adminLoading: false,
      roleAssignDialogVisible: false,
      roleAssignForm: {
        adminId: '',
        adminName: '',
        role: '',
        currentRoleName: ''
      },
      roleAssignRules: {
        role: [
          { required: true, message: '请选择角色', trigger: 'change' }
        ]
      },

      // 所有角色和角色资源
      allRoles: [],
      allRolesLoading: false,
      allRolesResources: [],
      allRolesResourcesLoading: false
    };
  },

  computed: {
    // 资源分页数据
    paginatedResourceList() {
      const start = (this.resourceCurrentPage - 1) * this.resourcePageSize;
      const end = start + this.resourcePageSize;
      return this.resourceList.slice(start, end);
    },

    // 角色资源分页数据
    paginatedRolesResources() {
      const start = (this.roleResourceCurrentPage - 1) * this.roleResourcePageSize;
      const end = start + this.roleResourcePageSize;
      return this.allRolesResources.slice(start, end);
    }
  },

  methods: {
    // ==================== 资源管理 ====================
    fetchResourceList() {
      this.resourceLoading = true;
      return axios.get('/zsd-permission/resource/selResource', {
        headers: {
          'token': localStorage.getItem('token')
        }
      })
      .then(response => {
        console.log('资源列表响应:', response.data);
        if (response.data.code === 200) {
          this.resourceList = response.data.data || [];
          console.log('资源列表数据:', this.resourceList);
          return this.resourceList;
        } else {
          this.$message.error(response.data.msg || '获取资源列表失败');
          return [];
        }
      })
      .catch(error => {
        console.error('获取资源列表失败:', error);
        this.$message.error('获取资源列表失败');
        return [];
      })
      .finally(() => {
        this.resourceLoading = false;
      });
    },

    handleAddResource() {
      this.resourceForm = {
        resourceId: null,
        name: '',
        resourceDesc: ''
      };
      this.resourceDialogVisible = true;
    },

    handleEditResource(row) {
      this.resourceForm = {
        resourceId: row.resourceId,
        name: row.name,
        resourceDesc: row.resourceDesc
      };
      this.resourceDialogVisible = true;
    },

    handleDeleteResource(row) {
      this.$confirm('确认删除该资源?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        axios.delete('/zsd-permission/resource/deleteResource', {
          params: { resourceId: row.resourceId },
          headers: {
            'token': localStorage.getItem('token')
          }
        })
        .then(response => {
          if (response.data.code === 200) {
            this.$message.success('删除成功');
            this.fetchResourceList();
          } else {
            this.$message.error(response.data.msg || '删除失败');
          }
        })
        .catch(error => {
          console.error('删除资源失败:', error);
          this.$message.error('删除失败');
        });
      }).catch(() => {});
    },

    resetResourceForm() {
      if (this.$refs.resourceFormRef) {
        this.$refs.resourceFormRef.resetFields();
      }
    },

    submitResourceForm() {
      this.$refs.resourceFormRef.validate(valid => {
        if (!valid) return;

        if (this.resourceForm.resourceId) {
          // 修改
          axios.post('/zsd-permission/resource/updateResource', null, {
            params: {
              resourceId: this.resourceForm.resourceId,
              name: this.resourceForm.name,
              resourceDesc: this.resourceForm.resourceDesc
            },
            headers: {
              'token': localStorage.getItem('token')
            }
          })
          .then(response => {
            if (response.data.code === 200) {
              this.$message.success('修改成功');
              this.resourceDialogVisible = false;
              this.fetchResourceList();
            } else {
              this.$message.error(response.data.msg || '修改失败');
            }
          })
          .catch(error => {
            console.error('修改资源失败:', error);
            this.$message.error('修改失败');
          });
        } else {
          // 新增
          axios.put('/zsd-permission/resource/addResource', null, {
            params: {
              name: this.resourceForm.name,
              resourceDesc: this.resourceForm.resourceDesc
            },
            headers: {
              'token': localStorage.getItem('token')
            }
          })
          .then(response => {
            if (response.data.code === 200) {
              this.$message.success('添加成功');
              this.resourceDialogVisible = false;
              this.fetchResourceList();
            } else {
              this.$message.error(response.data.msg || '添加失败');
            }
          })
          .catch(error => {
            console.error('添加资源失败:', error);
            this.$message.error('添加失败');
          });
        }
      });
    },

    // ==================== 角色资源管理 ====================
    fetchRoleResourceList() {
      this.roleResourceLoading = true;

      if (this.roleResourceQuery.rolesId === '') {
        this.$message.warning('请选择角色');
        this.roleResourceLoading = false;
        return;
      }

      // 清空之前的查询结果
      this.roleResourceList = [];

      // 确保先加载资源列表
      const loadResourcesFirst = this.resourceList.length === 0
        ? this.fetchResourceList()
        : Promise.resolve();

      loadResourcesFirst.then(() => {
        axios.get('/zsd-permission/roles-resource/selRolesResource', {
          params: { rolesId: this.roleResourceQuery.rolesId },
          headers: {
            'token': localStorage.getItem('token')
          }
        })
        .then(response => {
          console.log('角色资源查询结果:', response.data);
          if (response.data.code === 200) {
            const data = response.data.data;
            // 后端返回的是List<RolesResource>列表，直接赋值
            this.roleResourceList = Array.isArray(data) ? data : [];
            console.log('处理后的角色资源列表:', this.roleResourceList);

            if (this.roleResourceList.length === 0) {
              this.$message.info('未查询到该角色的资源');
            } else {
              this.$message.success(`查询到${this.roleResourceList.length}条该角色的资源`);
              // 强制更新视图
              this.$forceUpdate();
            }
          } else {
            this.$message.error(response.data.msg || '获取角色资源列表失败');
          }
        })
        .catch(error => {
          console.error('获取角色资源列表失败:', error);
          this.$message.error('获取角色资源列表失败');
        })
        .finally(() => {
          this.roleResourceLoading = false;
        });
      });
    },

    handleAddRoleResource() {
      this.roleResourceForm = {
        id: null,
        rolesId: '',
        resourceId: ''
      };
      this.roleResourceDialogVisible = true;
    },

    handleEditRoleResource(row) {
      this.roleResourceForm = {
        id: row.id,
        rolesId: row.roleId || row.rolesId,
        resourceId: row.resourceId
      };
      this.roleResourceDialogVisible = true;
    },

    handleDeleteRoleResource(row) {
      this.$confirm('确认删除该角色资源关联?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        axios.delete('/zsd-permission/roles-resource/deleteRolesResource', {
          params: { id: row.id },
          headers: {
            'token': localStorage.getItem('token')
          }
        })
        .then(response => {
          if (response.data.code === 200) {
            this.$message.success('删除成功');
            this.fetchRoleResourceList();
          } else {
            this.$message.error(response.data.msg || '删除失败');
          }
        })
        .catch(error => {
          console.error('删除角色资源关联失败:', error);
          this.$message.error('删除失败');
        });
      }).catch(() => {});
    },

    resetRoleResourceForm() {
      if (this.$refs.roleResourceFormRef) {
        this.$refs.roleResourceFormRef.resetFields();
      }
    },

    submitRoleResourceForm() {
      this.$refs.roleResourceFormRef.validate(valid => {
        if (!valid) return;

        if (this.roleResourceForm.id) {
          // 修改
          axios.post('/zsd-permission/roles-resource/updateRolesResource', null, {
            params: {
              id: this.roleResourceForm.id,
              resourceId: this.roleResourceForm.resourceId,
              rolesId: this.roleResourceForm.rolesId
            },
            headers: {
              'token': localStorage.getItem('token')
            }
          })
          .then(response => {
            if (response.data.code === 200) {
              this.$message.success('修改成功');
              this.roleResourceDialogVisible = false;
              this.fetchRoleResourceList();
            } else {
              this.$message.error(response.data.msg || '修改失败');
            }
          })
          .catch(error => {
            console.error('修改角色资源关联失败:', error);
            this.$message.error('修改失败');
          });
        } else {
          // 新增
          axios.put('/zsd-permission/roles-resource/addRolesResource', null, {
            params: {
              resourceId: this.roleResourceForm.resourceId,
              rolesId: this.roleResourceForm.rolesId
            },
            headers: {
              'token': localStorage.getItem('token')
            }
          })
          .then(response => {
            if (response.data.code === 200) {
              this.$message.success('添加成功');
              this.roleResourceDialogVisible = false;
              this.roleResourceQuery.rolesId = '';
              this.fetchRoleResourceList();
            } else {
              this.$message.error(response.data.msg || '添加失败');
            }
          })
          .catch(error => {
            console.error('添加角色资源关联失败:', error);
            this.$message.error('添加失败');
          });
        }
      });
    },

    resetRoleResourceQueryForm() {
      this.roleResourceQuery.rolesId = '';
      this.roleResourceList = [];
      // 重置后重新加载所有资源
      this.fetchAllRolesResources();
    },

    // ==================== 用户角色管理 ====================
    // 获取所有管理员列表
    fetchAllAdmins() {
      this.adminLoading = true;
      axios.get('/zsd-permission/admin-info/selAll', {
        headers: {
          'token': localStorage.getItem('token')
        }
      })
      .then(response => {
        console.log('管理员数据响应:', response);
        if (response.data && response.data.code === 200) {
          this.adminList = response.data.data || [];
          if (this.adminList.length === 0) {
            this.$message.warning('未查询到管理员数据');
          } else {
            this.$message.success('查询管理员数据成功');
          }
        } else {
          let msg = response.data && response.data.msg ? response.data.msg : '获取管理员列表失败';
          this.$message.error(msg);
          console.error('获取管理员列表响应错误:', response.data);
        }
      })
      .catch(error => {
        console.error('获取管理员列表失败:', error);
        this.$message.error('获取管理员列表失败: ' + (error.response && error.response.data && error.response.data.msg ? error.response.data.msg : error.message));
      })
      .finally(() => {
        this.adminLoading = false;
      });
    },

    // 弹出角色分配对话框
    handleAssignRole(row) {
      this.roleAssignForm = {
        adminId: row.adminId,
        adminName: row.name,
        role: row.role,
        currentRoleName: this.getRoleNameById(row.role)
      };
      this.roleAssignDialogVisible = true;
    },

    // 提交角色分配
    submitRoleAssign() {
      this.$refs.roleAssignFormRef.validate(valid => {
        if (!valid) return;

        axios.post('/zsd-permission/roles/updateRole', null, {
          params: {
            adminId: this.roleAssignForm.adminId,
            role: this.roleAssignForm.role
          },
          headers: {
            'token': localStorage.getItem('token')
          }
        })
        .then(response => {
          if (response.data.code === 200) {
            this.$message.success('角色分配成功');
            this.roleAssignDialogVisible = false;
            this.fetchAllAdmins();
          } else {
            this.$message.error(response.data.msg || '角色分配失败');
          }
        })
        .catch(error => {
          console.error('角色分配失败:', error);
          this.$message.error('角色分配失败');
        });
      });
    },

    // ==================== 角色和角色资源查询 ====================
    // 获取所有角色
    fetchAllRoles() {
      this.allRolesLoading = true;
      axios.get('/zsd-permission/roles/selAllRole', {
        headers: {
          'token': localStorage.getItem('token')
        }
      })
      .then(response => {
        if (response.data.code === 200) {
          this.allRoles = response.data.data || [];
        } else {
          this.$message.error(response.data.msg || '获取所有角色失败');
        }
      })
      .catch(error => {
        console.error('获取所有角色失败:', error);
        this.$message.error('获取所有角色失败');
      })
      .finally(() => {
        this.allRolesLoading = false;
      });
    },

    // 获取所有角色资源
    fetchAllRolesResources() {
      // 如果已经在查询特定角色资源，不要加载所有资源
      if (this.roleResourceQuery.rolesId !== '') {
        return;
      }

      this.allRolesResourcesLoading = true;
      axios.get('/zsd-permission/roles-resource/findAll', {
        headers: {
          'token': localStorage.getItem('token')
        }
      })
      .then(response => {
        if (response.data.code === 200) {
          this.allRolesResources = response.data.data || [];
        } else {
          this.$message.error(response.data.msg || '获取所有角色资源失败');
        }
      })
      .catch(error => {
        console.error('获取所有角色资源失败:', error);
        this.$message.error('获取所有角色资源失败');
      })
      .finally(() => {
        this.allRolesResourcesLoading = false;
      });
    },

    // 通过ID获取角色名称
    getRoleNameById(roleId) {
      const roleMap = {
        0: '超级管理员',
        1: '临时管理员',
        2: '负责人'
      };
      return roleMap[roleId] || `角色${roleId}`;
    },

    // 通过ID获取资源名称
    getResourceNameById(resourceId) {
      if (!resourceId) return '未知资源';

      const resource = this.resourceList.find(item => item.resourceId == resourceId);
      if (resource) {
        return resource.name;
      } else {
        console.warn(`未找到ID为${resourceId}的资源名称`);
        return `资源ID:${resourceId}`;
      }
    },

    // 通过ID获取资源描述
    getResourceDescById(resourceId) {
      if (!resourceId) return '';

      const resource = this.resourceList.find(item => item.resourceId == resourceId);
      if (resource) {
        return resource.resourceDesc;
      } else {
        console.warn(`未找到ID为${resourceId}的资源描述`);
        return '';
      }
    },

    // 资源分页处理
    handleResourceSizeChange(val) {
      this.resourcePageSize = val;
      this.resourceCurrentPage = 1; // 重置到第一页
    },

    handleResourceCurrentChange(val) {
      this.resourceCurrentPage = val;
    },

    // 角色资源分页处理
    handleRoleResourceSizeChange(val) {
      this.roleResourcePageSize = val;
      this.roleResourceCurrentPage = 1; // 重置到第一页
    },

    handleRoleResourceCurrentChange(val) {
      this.roleResourceCurrentPage = val;
    }
  },

  created() {
    this.fetchResourceList();
    this.fetchAllRoles();
    this.fetchAllRolesResources();
    this.fetchAllAdmins();
  },

  watch: {
    activeTab(newVal) {
      if (newVal === 'resource') {
        this.fetchResourceList();
      } else if (newVal === 'roleResource') {
        this.fetchRoleResourceList();
      } else if (newVal === 'userRole') {
        this.fetchAllAdmins();
      }
    }
  }
};
</script>

<style scoped>
.permission-container {
  padding: 20px;
}

.section-container {
  margin-top: 20px;
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  overflow-x: auto;
}

.header-actions {
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
}

.header-actions .el-button {
  padding: 10px 20px;
  font-weight: 500;
}

.query-form {
  margin-bottom: 25px;
  padding: 20px;
  background-color: #f5f7fa;
  border-radius: 8px;
}

.el-table {
  margin-top: 15px;
  border-radius: 8px;
  overflow: hidden;
}

.el-table th {
  background-color: #f5f7fa;
  color: #606266;
  font-weight: bold;
  padding: 12px 0;
}

.el-table td {
  padding: 12px 0;
}

/* 让表格更宽松，内容不会挤在前面 */
.el-table .cell {
  padding-left: 15px;
  padding-right: 15px;
  line-height: 1.5;
  word-break: break-word;
}

/* 表格按钮间距 */
.el-table .el-button {
  margin: 0 5px;
}

.el-table .el-button + .el-button {
  margin-left: 10px;
}

.dialog-footer {
  text-align: right;
  padding-top: 15px;
}

.pagination-container {
  margin-top: 30px;
  display: flex;
  justify-content: flex-end;
}

/* 标题样式 */
h3 {
  font-size: 18px;
  color: #303133;
  margin: 25px 0 15px;
  font-weight: 600;
  position: relative;
  padding-left: 15px;
  border-left: 4px solid #409EFF;
}

/* 对话框样式 */
:deep(.el-dialog__header) {
  padding: 20px;
  border-bottom: 1px solid #ebeef5;
}

:deep(.el-dialog__body) {
  padding: 30px 20px;
}

:deep(.el-dialog__title) {
  font-weight: bold;
  color: #303133;
}

/* 表单控件样式 */
:deep(.el-input__inner) {
  border-radius: 4px;
}

:deep(.el-form-item__label) {
  font-weight: 500;
}

/* 添加响应式支持 */
@media (max-width: 768px) {
  .section-container {
    padding: 15px;
  }

  .pagination-container {
    justify-content: center;
  }
}

/* 表格自适应布局 */
.table-adaptive {
  width: 100%;
  table-layout: fixed;
}

.table-adaptive .el-table__header-wrapper,
.table-adaptive .el-table__body-wrapper {
  width: 100%;
}

/* 表格内容超出显示省略号 */
.el-table .cell {
  padding-left: 15px;
  padding-right: 15px;
  line-height: 1.5;
  white-space: normal;
  word-break: break-word;
}

/* 资源描述列样式 */
.el-table .resource-desc-cell {
  white-space: normal;
  line-height: 1.5;
  max-height: 4.5em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* 确保操作列的按钮紧凑排列 */
.el-table .el-button {
  margin: 0 5px;
  padding: 7px 12px;
}

/* 防止表格横向溢出 */
@media (max-width: 1200px) {
  .el-table .el-button {
    padding: 7px 10px;
    font-size: 12px;
  }
}
</style>
